package com.bawei.patient.service.impl;

import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bawei.common.utils.PageUtils;
import com.bawei.common.utils.Query;

import com.bawei.patient.dao.PatientDao;
import com.bawei.patient.entity.PatientEntity;
import com.bawei.patient.service.PatientService;


@Service("patientService")
public class PatientServiceImpl extends ServiceImpl<PatientDao, PatientEntity> implements PatientService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<PatientEntity> wrapper = new QueryWrapper<>();


        String key =(String)params.get("key");
        if (key!=null && key!=""){

            QueryWrapper<PatientEntity> patient_name = wrapper.like("patient_name", key).or()
                    .like("patient_phone", key);
            try {
                Integer id = Integer.parseInt(key);
                patient_name.or().eq(" id",id);
            }catch (NumberFormatException exception){
                exception.printStackTrace();
            }
        }






        IPage<PatientEntity> page = this.page(
                new Query<PatientEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

}